﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GuessLAB.Domain;
using System.Utility.UI;
using System.Utility.Messaging;
using System.Utility;
using System.Web.Security;

namespace GuessLAB.UI
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                AppUser u = AppUser.AddUser(usernamesignup.Value, firstName.Value, lastName.Value, emailsignup.Value, passwordsignup.Value);
                if (u != null)
                {
                    StateManager<AppUser>.SetSessionState(SessionKey.UserInfo, u);
                    FormsAuthentication.SetAuthCookie(u.FirstName + " " + u.LastName, createPersistentCookie: false);
                    Response.Redirect("Home.aspx", false);
                }
                else
                {
                    Logger.LogMessage("throwing messsage", LogLevel.DEBUG, LogMessageType.WebMessage);
                    PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
                }
            }
            catch (Exception ex)
            {
                string msgCode = MessageUtility.LogAndGetMessageCode(ex);
                PageUtility.RegisterClientScriptBlockByMessageId(this, msgCode);
            }
        }
    }
}